import type { BaseEntity, ID, PageQuery, PageResult } from '#/api/common';

import { requestClient } from '#/api/request';

export interface OAuth2Client extends BaseEntity {
  id: ID;
  clientName: string;
  status: string;
  clientId: string;
  clientSecret: string;
  scopes: string[];
  authorizationGrantTypes: string[];
  redirectUris: string[];
  autoApprove: boolean;
}

const baseUrl = `/ur_biz/oauth2_client`;

/** 客户端分页列表 */
export function listClient(query?: PageQuery) {
  return requestClient.get<PageResult<OAuth2Client>>(`${baseUrl}/list`, {
    params: query,
  });
}

/** 查询客户端详细 */
export function getClient(id: ID) {
  return requestClient.get<OAuth2Client>(`${baseUrl}/${id}`);
}

/** 新增客户端 */
export function addClient(data: OAuth2Client) {
  return requestClient.post(`${baseUrl}/add`, data);
}

/** 修改客户端 */
export function editClient(data: OAuth2Client) {
  return requestClient.post(`${baseUrl}/edit`, data);
}

/** 删除客户端 */
export function delClient(id: ID) {
  return requestClient.post(`${baseUrl}/remove`, id);
}

/** 用户状态修改 */
export function changeStatus(id: ID, status: string) {
  return requestClient.post(`${baseUrl}/edit_status`, {
    id,
    status,
  });
}
